package com.april.pattern.structural.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @author April
 * @version V1.0.0
 * @date 2019/07/04 16:38
 * @description
 */
public class FolderImpl extends AbstractFileCombination {
    private String name;

    /**
     * 定义容器，用来存放容器构建下的子节点
     */
    private List<AbstractFileCombination> fileList = new ArrayList<>();

    public FolderImpl(String name) {
        this.name = name;
    }

    @Override
    public void add(AbstractFileCombination addFile) {
        fileList.add(addFile);
    }

    @Override
    public void remove(AbstractFileCombination removeFile) {
        fileList.remove(removeFile);
    }

    @Override
    public AbstractFileCombination getFile(int index) {
        return fileList.get(index);
    }

    @Override
    public void killVirus() {
        System.out.println("----文件夹：" + this.name + "，进行查杀");
        for (AbstractFileCombination abstractFile : fileList) {
            abstractFile.killVirus();
        }
    }
}
